/*
 * @lc app=leetcode.cn id=4 lang=javascript
 *
 * [4] 寻找两个正序数组的中位数
 */

// @lc code=start
/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number}
 */
var findMedianSortedArrays = function(nums1, nums2) {
    let point1=0
    let point2=0
    let arr=[]
    let mid=(nums1.length+nums2.length)/2
    while(true){
        if(nums1[point1]==undefined){
            arr.push(nums2[point2])
            point2++
        }else if(nums2[point2]==undefined){
            arr.push(nums1[point1])
            point1++
        }
        else if(nums1[point1]<=nums2[point2]){
            arr.push(nums1[point1])
            point1++
        }else{
            arr.push(nums2[point2])
            point2++
        }
        let l=arr.length-1
        if(l==(mid|0)){
            if(mid==(mid|0)){
                return (arr[l]+arr[l-1])/2
            }else{
                return arr[l]
            }
        }
    }
};
// @lc code=end

findMedianSortedArrays([1,3],[2])